/**
 * 
 */
package org.cmcc.pcap.jpcap.tcp;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import jpcap.packet.TCPPacket;

/**
 * @Date 2018年4月19日 下午3:29:10
 * @author Amish
 */
public class TcpProducer  implements Runnable{
	private static Logger logger = LogManager.getLogger(TcpProducer.class);

     private TCPPacket tcpPacket;
     private TcpConnectionCache tcpConnectionCache;

     
     public TcpProducer( TCPPacket tcpPacket,TcpConnectionCache tcpConnectionCache) {
    	 this.tcpPacket = tcpPacket;
    	 this.tcpConnectionCache = tcpConnectionCache;
     }
     
	@Override
	public void run() {
		try{
			TcpPacketDecorator tcpPacketDecorator; 
			boolean isFirst = false;
			if( tcpPacket.syn && !tcpPacket.ack){//第一条TCP消息，TCP三次握手第一条消息, syn为1 ack为0
				logger.debug("receive the first tcp message : "+ tcpPacket.sequence);
				isFirst = true;
			}
			tcpPacketDecorator = new TcpPacketDecorator(isFirst);
			tcpPacketDecorator.tcpPacket = tcpPacket;
			tcpConnectionCache.addTcpPacketDecorator(tcpPacketDecorator);
		}catch(Exception e){
			logger.error("TcpHandler has some exception : ",e);
		}
	}

	
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}
}
